package com.LFLWZ.utils;


import com.cloopen.rest.sdk.BodyType;
import com.cloopen.rest.sdk.CCPRestSmsSDK;

import java.util.HashMap;

public class SendMsgUtil {

    //生产环境请求地址：app.cloopen.com
    private static final String serverIp = "app.cloopen.com";
    //请求端口
    private static final String serverPort = "8883";
    //主账号,登陆云通讯网站后,可在控制台首页看到开发者主账号ACCOUNT SID和主账号令牌AUTH TOKEN
    private static final String accountSId = "8aaf0708747ac63201747c5d932d013f";
    private static final String accountToken = "4b8f736524584408a2547b0a8418f7d5";
    //请使用管理控制台中已创建应用的APPID
    private static final String appId = "8aaf0708747ac63201747c5d945d0145";

    /**
     * 发送短消息
     * @param toFhone     接收者手机号
     * @param templateId  短信模板id
     * @param datas       短信中数据
     * @return
     */
    public static Boolean send(String toFhone,String templateId,String... datas){

        CCPRestSmsSDK sdk = new CCPRestSmsSDK();
        sdk.init(serverIp, serverPort);
        sdk.setAccount(accountSId, accountToken);
        sdk.setAppId(appId);
        sdk.setBodyType(BodyType.Type_JSON);
        //String to = "19174873141";
        //String templateId= "1";
        //String[] datas = {"2020","2020"};
        String subAppend="1234";  //可选 扩展码，四位数字 0~9999
        String reqId="fadfafas";  //可选 第三方自定义消息id，最大支持32位英文数字，同账号下同一自然天内不允许重复
        //HashMap<String, Object> result = sdk.sendTemplateSMS(to,templateId,datas);
        HashMap<String, Object> result = sdk.sendTemplateSMS(toFhone,templateId,datas);
        if("000000".equals(result.get("statusCode"))){
            //正常返回输出data包体信息（map）
            return true;
        }else{
            //异常返回输出错误码和错误信息
            System.out.println("错误码=" + result.get("statusCode") +" 错误信息= "+result.get("statusMsg"));
            return false;
        }
    }
}
